/* eslint-disable max-classes-per-file */
/*
 * @Description:
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2023-08-16 17:36:20
 * @LastEditors: wiz
 * @LastEditTime: 2023-12-16 11:18:02
 */
import { N_oSetupPanel } from '../../types';
import { T_compPanelConf } from '../compConfPanel';
import { T_toolbarLib } from '../compToolbar';
import { T_compBase } from './compBase';

type I_tableStyle = N_oSetupPanel.N_comps.I_tableStyle;
type I_compToolbar = N_oSetupPanel.N_comps.I_compToolbar;
type I_messageConf = N_oSetupPanel.N_comps.I_messageConf;
export class T_treeGridConf {
  name: string;

  comment: string;

  isCreated: boolean;

  status: string;

  dbType: 'mysql' | 'mongo';

  tableStyle: I_tableStyle;

  tableColumns: Array<any>;

  uniqueIndexes: Array<any>;

  indexes: Array<any>;

  rules: Array<any>;

  toolbar: I_compToolbar;

  tableDataSetting: object;

  tableDataSource: {
    main: {
      name: string;
      fields: Array<{
        field: string;
        keyField: boolean;
        childField: boolean;
        isShow: boolean;
        filter: object;
      }>;
    };
  };

  messageConfig: I_messageConf;
}
export class T_treeGrid extends T_compBase {
  private TcompPanelConf: T_compPanelConf = new T_compPanelConf();

  private TtoolbarLib: T_toolbarLib = new T_toolbarLib();

  public conf: T_treeGridConf = new T_treeGridConf();

  constructor() {
    super();
    this.conf = {
      name: '',
      comment: '',
      isCreated: false,
      status: '',
      dbType: N_oSetupPanel.N_comps.DB_TYPE.MYSQL,
      tableStyle: {
        showHeader: true,
        showFooter: false,
        showToolbar: true,
        border: true,
        mode: N_oSetupPanel.N_comps.TABLESTYLE_MODE.MODE_NAV
      },
      tableColumns: [],
      uniqueIndexes: [],
      indexes: [],
      rules: [],
      toolbar: null,
      tableDataSetting: {
        editable: true
      },
      tableDataSource: {
        main: {
          name: '',
          fields: []
        }
      },
      messageConfig: {
        custDefListener: {
          search: [],
          coordination: null
        },
        emitActions: {
          search: [],
          refresh: []
        },
        eventGroup: null
      }
    };
    this.conf.toolbar = this.TtoolbarLib.getCompToolBarSet(
      N_oSetupPanel.N_comps.COMP_NAME.TREE_GRID
    );
  }

  public getPermissionList(
    config: T_treeGridConf
  ): Array<N_oSetupPanel.I_permission> {
    return [];
  }

  public addTableColumn(...p: any[]): void {
    this.conf.tableColumns.push(...p);
  }

  public addUniqueIndexes(...p: any[]): void {
    this.conf.uniqueIndexes.push(...p);
  }

  public addIndexes(...p: any[]): void {
    this.conf.indexes.push(...p);
  }

  public addRules(...p: any[]): void {
    this.conf.rules.push(...p);
  }

  public getComponentId(): N_oSetupPanel.N_comps.COMP_MODULE_ID {
    return N_oSetupPanel.N_comps.COMP_MODULE_ID.BASE_GRID;
  }

  public getConf(): T_treeGridConf {
    return this.conf;
  }

  public GetCompPanelConf(): N_oSetupPanel.N_comps.I_setupPanel {
    return this.TcompPanelConf.getCompPanelSet(
      N_oSetupPanel.N_comps.COMP_NAME.TREE_GRID
    );
  }
}
